package com.fengkai.filepost.pdfoutstream.test.ODsolutions;

import org.junit.Test;

/**
 * @author Fengkai
 * @creat 2023/4/10 0010
 * 输入描述:
 * 一个目标整数 T (1 <=T<= 1000)
 * 输出描述:
 * 该整数的所有表达式和表达式的个数。如果有多种表达式，输出要求为：
 * 1.自然数个数最少的表达式优先输出
 * 2.每个表达式中按自然数递增的顺序输出，具体的格式参见样例。在每个测试数据结束时，输出一行”Result:X”，其中 X 是最终的表达式个数
 */
public class SumForLianxu {

    public static void main (String[] args) {


    }

    public static int getResult (Integer sum) {
        // (x + (x + k - 1)) * k / 2 = sum
        // (2x + k - 1) * k / 2 = sum
        // 2x + k -1 = 2sum/k
        // 2x = 2sum/k + 1 -k
        // x = sum/k + 1/2 - k/2
        //k <= sum / 2
        //等差数列和
        int count = 0;
        double input = sum;
        for (int i = 1; i <= sum/2; i++) {
            double j = i;
            double x =  sum/j + 0.5 - j/2;
            if (x % 1 == 0 && x > 0){
                StringBuilder stringBuilder = new StringBuilder();
                stringBuilder.append(sum + "=");
                count ++;
                int first = (int) x;
                for (int k = 0; k < i; k++) {
                    stringBuilder.append(first ++ + "+");
                }
                System.out.println(stringBuilder.substring(0, stringBuilder.length() - 1));
            }
        }

        System.out.println("Result:" + count);
        return count;
    }

    @Test
    public void test () {
        double l = 2.5;
        getResult(100);
    }
}
